// JavaScript Document
;(function($){
		   $.fn.jTab=function(options){
			   var settings={
				   actionType:"click",defaultSelectedTab:"",selectedClassSuffix:"",transitionType:"",speed:"fast",onShowTabCallBack:null
				   }
			   var op=$.extend(settings,options);
			   var oldobj=null;
			   var $this=$(this);
			   
			   
			   var showTabcontent=function(obj,callback){

				   $this.find("#"+$(obj).attr("rel")).show();

				   }
			   var showHiddenTabcontent=function(obj){
				   if ($this.find("#tabcontent:first > .tab:visible").attr("id")==$(obj).attr("rel")){ //在同一个Tab上动作，就不执行显示隐藏内容动作
					   return false;
					   }
				   switch (op.transitionType){
					   case "slide":
					   			$this.find("#tabcontent:first > .tab:visible").slideUp(op.speed,function(){
																										 $this.find("#"+$(obj).attr("rel")).slideDown(op.speed,
																																					  function(){if ($.isFunction(op.onShowTabCallBack)) op.onShowTabCallBack(obj)}
																																					  );
																										 
																										 });
								break;
					   case "fade":			   
					   			$this.find("#tabcontent:first > .tab:visible").fadeOut(op.speed,function(){
																										 $this.find("#"+$(obj).attr("rel")).fadeIn(op.speed,
																																					  function(){if ($.isFunction(op.onShowTabCallBack)) op.onShowTabCallBack(obj)}
																																					  );
																										 });
								break;
//					   case "show":
//					   			alert("show");					   
//					   			$this.find("#tabcontent:first > div:visible").hide(op.speed);
//								break;
					   default :			   
					   			$this.find("#tabcontent:first > .tab:visible").hide();$this.find("#"+$(obj).attr("rel")).show();
								if ($.isFunction(op.onShowTabCallBack)) op.onShowTabCallBack(obj)
								break;
					   }
				   
				   
				   }

			   var changeTabClass=function(obj){ //改进 未作。可以考虑用showTabcontent的方法来改进
				   if (op.selectedClassSuffix!=""){
					   if ($(obj).hasClass($(obj).attr("rel")+op.selectedClassSuffix)){
						   $(obj).removeClass($(obj).attr("rel")+op.selectedClassSuffix);
						   }
					   else{
						   $(obj).addClass($(obj).attr("rel")+op.selectedClassSuffix);
						   }

					   }
				   else{
					   $(obj).toggleClass("current");
					   }
				   if ($(obj).find("input[type=radio]").length>0){
					   $(obj).find("input[type=radio]").attr("checked","checked")
					   }
				   }
			   var initTabcontent=function(){
				   $this.find("#tabcontent:first").children(".tab").each(function(){
																				  if ($(this).attr("id")!=op.defaultSelectedTab){$(this).hide();}
																				  })
				   }
			   
			   initTabcontent();
			   return $(this).find("#tabs:first").find("li").each(function(i){
																		   
																		   
																		   
														  if ($(this).attr("rel")==op.defaultSelectedTab){
															  oldobj=this;
															  changeTabClass(this);

															  }
														  $(this).bind(op.actionType,function(){
																							  var nowobj=this;
																							  if (oldobj==null){
																								  oldobj=this;
																								  changeTabClass(this);
																								  
																								  }
																							  else{
																								  //隐藏老的内容，然后显示新的
																								  changeTabClass(oldobj);
																								  changeTabClass(this);
																								  showHiddenTabcontent(this)
																								  oldobj=this;
																								  } 

																							  return false;
																							  })
														  
														  })
			   
			   
			   
			   }
		   
		   
		   
		   })( jQuery );